<template>
	<view class="page">
		<!-- 轮播图区域 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" indicator-color="#fff" class="carousel">
			<swiper-item v-for="item in carouselList" :key="item.id">
				<image :src="item.image" class="carousel"  @click = "toMovieDeatil" :data-trailerId = "item.movieId"></image>
			</swiper-item>
		</swiper>

		<!-- 热门超英start -->
		<view class="page-block super-hot">
			<view class="hot-title-wa">
				<image class="img" src="../../static/icon/hot-icon.png"></image>
				<view class="text">热门超英</view>
			</view>
			<scroll-view class="page-block hot" scroll-x="true">
				<view class="hot-item" v-for="item in hotMovieData" :key="item.id">
					<image class="item-img" :src="item.cover" mode=""  @click = "toMovieDeatil" :data-trailerId = "item.id"></image>
					<view class="movie-name">{{item.name}}</view>
					<start :rote="item.score"></start>
				</view>
			</scroll-view>
		</view>


		<!-- 热门超英电影预告-->
		<view class="page-block super-hot ">
			<view class="hot-title-wa">
				<image class="img" src="../../static/icon/trailer-icon.png"></image>
				<view class="text">超英预告</view>
			</view>
			<view class="trailer-wr">
				<video class="trailer" :src="trailer.trailer" :poster="trailer.poster" v-for=" trailer in trailerMovieData"
				 controls></video>
			</view>
		</view>

		<!-- 猜你喜欢 -->
		<view class="page-block like">
			<view class="hot-title-wa">
				<image class="img" src="../../static/icon/like-icon.png"></image>
				<view class="text">猜你喜欢</view>
			</view>
			<view class="like-content">
				<view class="like-item" v-for="(item,index) in guesslikeData">
					<view class="like-left">
						<view  class ="like-img-wr">
							<image class="like-img" :src="item.cover"  @click = "toMovieDeatil" :data-trailerId = "item.id"
							></image>
						</view>
						
						<view class="like-info">
							<h2 class="like-title">{{item.name}} </h2>
							<start :rote="9.1"></start>
							<text class="movie-addre"> {{item.basicInfo}}</text>
							<text class="release-time">{{item.releaseDate}}</text>
						</view>
					</view>
					<view class="btn-thumbs-up">
					
						 <image class="thumbs-img" src="../../static/icon/thumbs.png" :data-index="index" mode="" @click="timingAdd"></image>
						 <text  class="thumbs-text">赞一下</text>
						
						 <view :animation="animationDataArr[index]" class="add1" >+1</view>
						 
						 <view class="texth5" :class = "{h5animation:isShowAnimation && h5==index}" ref= "h5" data-index ="index" >+1</view>
						
					</view>
				</view>

			</view>



		</view>

	</view>
</template>

<script>
	import Start from '../../components/Start'
	export default {
		data() {
			return {
				//轮播图数据
				carouselList: [],
				//热点电影数据
				hotMovieData: [],
				//电影预告数据
				trailerMovieData: [],
				//动画数据
				animationDataArr:[{},{},{},{},{}],
				animationData:{},
               //猜你喜欢
			    guesslikeData:[],
				// h5animation:{
				// 	position: "absolute",
				// 	top:"120upx",
				// 	opacity: "0",
				// 	transitionProperty: "top",
				// 	transitionDuration: ".3s",
				// 	fontSize:'20px',
				// 	// color:"#ffbe34"
				// 	color:"#00000"
					
				// },
				h5:0,
				isShowAnimation:false,
				hideText:{
					opacity:"0"
				}
			}
		},
		onLoad() {
			this.getSwiperListData();
			this.getHotMovieData();
			this.getHotMovieTrailerData();
			this.getGuessUlikeData();
			//#ifdef APP-PLUS || MP-WEIXIN
			this.initAnimation();
			//#endif
			
			console.log(this.carouselList);
			
		},
		onUnload(){
			this.animationDataArr=[],
			this.animationData={}
		},
		onPullDownRefresh(){
			this.getGuessUlikeData()
		},
		methods: {
			//获取轮播图数据方法
			getSwiperListData() {
				uni.request({
					method: 'POST',
					url: this.serverUrl + '/index/carousel/list?qq=3316368400',
					success: (res) => {
						let data = res.data;
						if (data.status !== 200) return;
						this.carouselList = data.data;
						console.log(data.data);
					


					}
				})
			},
			//获取热点漫威电影预告的方法
			getHotMovieData() {
				uni.request({
					method: 'POST',
					url: this.serverUrl + '/index/movie/hot?type=superhero&qq=3316368400',
					success: (res) => {
						let data = res.data;
						if (data.status !== 200) return;
						this.hotMovieData = data.data
					}
				})
			},
			//获取热点漫威电影的方法
			getHotMovieTrailerData() {
				uni.request({
					method: 'POST',
					url: this.serverUrl + '/index/movie/hot?type=trailer&qq=3316368400',
					success: (res) => {
						let data = res.data;
						if (data.status !== 200) return;
						this.trailerMovieData = data.data;
					}
				})
			},
			getGuessUlikeData(){
			   uni.showLoading({
				   mask:true
			   });
				uni.request({
					method:'POST',
					url:this.serverUrl+'/index/guessULike?qq=3316368400',
					success:(res)=>{
						var data = res.data;
						if(data.status !==200) return;
						   this.guesslikeData =  data.data;
						   
					},
					complete:()=>{
						uni.hideLoading()
						uni.stopPullDownRefresh();
					}
				})
			},
			//点击点赞方法
			timingAdd(e){
					let i = e.currentTarget.dataset.index;
					//#ifdef APP-PLUS || MP-WEIXIN
				 this.animation.opacity(1).translateY(-95).step({
				       duration: 500,
				       timingFunction: 'inear'
				   });
				 
				 setTimeout(()=>{
					 this.animation.opacity(0).translateY(95).step({
					  duration:0,
				     
				   });
					  this.animationData = this.animation;
					  this.animationDataArr[i] = this.animationData.export()
				 },400);
				  this.animationData = this.animation;
				  this.animationDataArr[i] = this.animationData.export();
				  	//#endif
					
					//#ifdef H5
							  this.h5 = i;
							  this.$nextTick(()=>{
								      this.isShowAnimation = true;
									    if(this.isShowAnimation){
											setTimeout(()=>{
												this.isShowAnimation = false;
											},300)
										}
						  })				 
					//#endif
			},
			//初始化动画方法
			initAnimation(){
				 this.animation = uni.createAnimation();
			},
			toMovieDeatil(e){
				let id = e.currentTarget.dataset.trailerid;
				uni.navigateTo({
				    url: '../movie/movie?trailerId='+id
				});
			}

		},
		components: {
			Start
		}
	}
</script>

<style>
	@import url("./index.css");
	

	

</style>
